package cn.jdy.plugins.service;

import java.util.List;

import org.hibernate.SQLQuery;
import org.springframework.stereotype.Service;

import cn.jdy.framework.db.hibernate.BaseDao;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.plugins.entity.Attachment;

@Service
public class AttachmentService extends BaseDao<Attachment> {

	/**
	 * 根据品牌ID 查询荣誉证书附件
	 * @param brandId
	 * @return
	 */
	public List<Attachment> findAttachmentByBrandId(Integer brandId){
		List<Attachment> list = null;
		try {
		  SQLQuery query = super.em().createSQLQuery("Select t.id,t.attachment_type,t.attachment_size,t.attachment_path,t.post_time,t.is_del,t.attachment_name,t.OriginaFilename " +
					"from Attachment t ,BrandCredit tt where t.id =tt.attchmentid and t.attachment_path is not null and t.attachment_path <> '' and brandId = ? order by t.post_time ");
			query.setParameter(1, brandId);
			query.addEntity(Attachment.class);
			list = query.list();

		} catch (Exception e) {
			BaseLog.e(this.getClass(), "根据品牌ID 查询荣誉证书附件失败", e);
		}
		return list;
	}
	/**
	 * 根据品牌ID 查询荣誉证书附件（包括空的，供企业申请使用）
	 * @param brandId
	 * @return
	 */
	public List<Attachment> findAllAttachmentByBrandId(Integer brandId){
		List<Attachment> list = null;
		try {
		  SQLQuery query = super.em().createSQLQuery("Select t.id,t.attachment_type,t.attachment_size,t.attachment_path,t.post_time,t.is_del,t.attachment_name,t.OriginaFilename " +
					"from Attachment t ,BrandCredit tt where t.id =tt.attchmentid and tt.brandId =? order by id");
			query.setParameter(0, brandId);
			query.addEntity(Attachment.class);
			list = query.list();

		} catch (Exception e) {
			BaseLog.e(this.getClass(), "根据品牌ID 查询荣誉证书附件失败", e);
		}
		return list;
	}
}
